package com.ruoyi.business;

import Ice.Communicator;
import Ice.InitializationData;
import com.ruoyi.business.PortServerIce.QueryServantPrx;
import com.ruoyi.business.enumType.PSIceOrderType;
import com.ruoyi.business.helper.QueryServantPrxHelper;
import com.ruoyi.business.*;
import com.ruoyi.business.dto.*;
import com.ruoyi.business.holder.*;

import java.time.Instant;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;


/**
 * @Program:iceTest
 * @description:
 * @author: ronghaohua
 * @create: 2024-04-12 14:54:51
 **/
public class QueryOrderClient {
    public static void main(String[] args) {
        InitializationData initData = new InitializationData();
        Communicator communicator = Ice.Util.initialize(initData);

        try {
            //本机调用 TradeServantService:default -p 9000
//            TradeServantPrx tradeServantPrx = TradeServantPrxHelper.checkedCast(communicator.stringToProxy("TradeService:tcp -h 192.168.0.101  -p 60010"));
            QueryServantPrx queryServantPrx = QueryServantPrxHelper.checkedCast(communicator.stringToProxy("QueryService:tcp -h 192.168.0.101  -p 60010"));

            long epochSecond = Instant.now().getEpochSecond();
            if (queryServantPrx == null) {
                System.err.println("Invalid proxy");
                System.exit(1);
            }
            PSIceOrderContractListHolder psIceOrderContractListHolder = new PSIceOrderContractListHolder();
            PSIceTradeDetailListHolder psIceTradeDetailListHolder = new PSIceTradeDetailListHolder();

            PSIceErrorCodeHolder psIceErrorCodeHolder = new PSIceErrorCodeHolder();
            PSIceOrderContractSearch psIceOrderContractSearch = new PSIceOrderContractSearch("0", PSIceOrderType.Buy.value(),0, "512660",15000,17000);
            PSIceOrderDetailListHolder psIceOrderDetailListHolder = new PSIceOrderDetailListHolder();
            PSIceTransDetailListHolder psIceTransDetailListHolder = new PSIceTransDetailListHolder();
            int date = Integer.parseInt(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")));

            int i = queryServantPrx.GetOrderContractList(new PSIceAccount(), psIceOrderContractSearch, psIceOrderContractListHolder, psIceErrorCodeHolder);
            int i1 = queryServantPrx.GetOrderDetailList(date, new PSIceAccount(), "0",psIceOrderDetailListHolder, psIceErrorCodeHolder);
            int i2 = queryServantPrx.GetTransDetailList((int) epochSecond, new PSIceAccount(), "0",psIceTransDetailListHolder, psIceErrorCodeHolder);
            int i3 = queryServantPrx.GetTradeDetailList(1, new PSIceAccount(), "0",psIceTradeDetailListHolder, psIceErrorCodeHolder);
            // 委托状态

//            PSIceOrderSearch psIceOrderSearch = new PSIceOrderSearch("1","F2-58340bd5-5dd3-4e5e-a5ec-af682e463c8b","512000",0);
            PSIceOrderSearch psIceOrderSearch = new PSIceOrderSearch();

            PSIceOrderStatusListHolder psIceOrderStatusListHolder = new PSIceOrderStatusListHolder();
            PSIceTransStatusListHolder psIceTransStatusListHolder = new PSIceTransStatusListHolder();


            // 成交
            int i4 = queryServantPrx.GetTodayOrderStatusList( new PSIceAccount(), psIceOrderSearch,psIceOrderStatusListHolder, psIceErrorCodeHolder);
            // 委托
            int i5 = queryServantPrx.GetTodayTransStatusList( new PSIceAccount(), psIceOrderSearch,psIceTransStatusListHolder, psIceErrorCodeHolder);




            PSIceOrderContract[] value = psIceOrderContractListHolder.value;
            PSIceOrderDetail[] value1 = psIceOrderDetailListHolder.value;
            PSIceTransDetail[] value2 = psIceTransDetailListHolder.value;
            PSIceTradeDetail[] value3 = psIceTradeDetailListHolder.value;
            PSIceTransStatus[] value4 = psIceTransStatusListHolder.value;
            System.out.println(i1);
            System.out.println(i2);
            System.out.println(i3);

        } finally {
            communicator.destroy();
        }
    }
}
